import { createBrowserRouter, Navigate } from 'react-router-dom'
import MyLayout from '../layout'
import Home from '../pages/home' 
import User from '../pages/user'
import Menu from '../pages/menu'
import Role from '../pages/role'
import Login from '../pages/login'
import config from '../config'

const router = createBrowserRouter([
    {
        path: '/login',
        element: <Login />
    },
    {
        path: '/',
        element: <MyLayout />,
        children: [
            {
                path: '/',
                element: <Navigate to='home' replace />
            },
            {
                path: '/home',
                element: <Home />
            },
            {
                path: '/user',
                element: <User />
            },
            {
                path: '/role',
                element: <Role />
            },
            {
                path: '/menu',
                element: <Menu />
            }
        ]
    }
])

export default router;

export function PrivateRoute(props){
    return localStorage.getItem(config.SESSION_INFO) ? (props.children) :( <Navigate to="/login" />)
}
